//Given an integer columnNumber, return its corresponding column title as it app
//ears in an Excel sheet. 
//
// For example: 
//
// 
//A -> 1
//B -> 2
//C -> 3
//...
//Z -> 26
//AA -> 27
//AB -> 28 
//...
// 
//
// 
// Example 1: 
//
// 
//Input: columnNumber = 1
//Output: "A"
// 
//
// Example 2: 
//
// 
//Input: columnNumber = 28
//Output: "AB"
// 
//
// Example 3: 
//
// 
//Input: columnNumber = 701
//Output: "ZY" 26*26+25
// 
//
// Example 4: 
//
// 
//Input: columnNumber = 2147483647
//Output: "FXSHRXW"
// 
//
// 
// Constraints: 
//
// 
// 1 <= columnNumber <= 231 - 1 
// 
// Related Topics 数学 
// 👍 343 👎 0


package leetcode.editor.cn;

import org.junit.Assert;

//Java：Excel Sheet Column Title
class P168ExcelSheetColumnTitle {
    public static void main(String[] args) {
        Solution solution = new P168ExcelSheetColumnTitle().new Solution();
        // TO TEST
        Assert.assertEquals(solution.convertToTitle(27), "AA");
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String convertToTitle(int columnNumber) {
            if (columnNumber <= 0) {
                return "";
            }
            StringBuilder sb = new StringBuilder();
            while (columnNumber != 0) {
                columnNumber--;
                sb.append((char) ('A' + columnNumber % 26));
                columnNumber /= 26;
            }
            return sb.reverse().toString();
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}